using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BaseForum.Model;
using BaseForum.Mockup;
using BaseForum.Dao;

namespace WebForum.App_Data
{
    public class UserDataSource
    {
        private static readonly UserDao userDao = new UserDao();

        /// <summary>
        /// Get all User
        /// </summary>
        /// <returns></returns>
        public static List<User> ListUsers()
        {
            //List<User> users = WebForumMockup.users;
            List<User> users = userDao.List();
            return users;
        }
        /// <summary>
        /// Insert new user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool Insert(User user)
        {
            //user.Id = WebForumMockup.users.Count + 1;
            //WebForumMockup.users.Add(user);
            //return user;
            return userDao.Insert(user);
        }
        /// <summary>
        /// Get user by user name  - not use
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static User Get(String userName)
        {
            foreach (User u in WebForumMockup.users)
            {
                if (userName == u.UserName)
                    return u;
            }
            return null;
        }
        /// <summary>
        /// Get user
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static User Get(Int32 id)
        {
            return userDao.Get(id);
        }

        /// <summary>
        /// Count user
        /// </summary>
        /// <returns></returns>
        public static int Count()
        {
            //return WebForumMockup.users.Count;
            return userDao.List().Count;
        }

        /// <summary>
        /// Login
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static User Login(String username, String password)
        {
            return userDao.Login(username, password);
        }
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool Update(User user)
        {
            return userDao.Update(user);
        }
        /// <summary>
        /// Delete user
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Delete(int id)
        {
            return userDao.Delete(id);
        }
        /// <summary>
        /// change password
        /// </summary>
        /// <param name="id"></param>
        /// <param name="oldPass"></param>
        /// <param name="newPass"></param>
        /// <returns></returns>
        public static bool ChangePass(int id,string oldPass,string newPass)
        {
            return userDao.ChangePassword(id, oldPass, newPass);
        }
    }
}
